package com.training.java.core.collections.car.pre15;

//Purpose of this demo is to observe how Set Collection ,HashSet,LinkedHashSet,working.

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

public class FruitSetHashSetDemo {

	public static void main(String[] args) {
		// public static void main(String[] args) {
		// Instantiating multiple objects Fruit1, Fruit2,Fruit3,Fruit4

		Fruit fruit1 = new Fruit("Custard Apple", "Green", "Sweet", 1);
		Fruit fruit2 = new Fruit(" Apple", "Green", "Sweet", 2);
		Fruit fruit3 = new Fruit("Banana", "Yellow", "Sweet", 1);
		Fruit fruit4 = new Fruit("Mango", "Yellow", "Sweet", 30);
		Fruit fruit5 = new Fruit("Persimon", "Orange", "Sweet", 5);

		// Creating a collection using the set

		Set listOfFruits = new HashSet();

		// Creating collection using the Linked set

		// Set listOfFruits = new LinkedHashSet();

		// adding the objects to the container/List
		listOfFruits.add(fruit1);
		listOfFruits.add(fruit2);
		listOfFruits.add(fruit3);
		listOfFruits.add(fruit4);
		listOfFruits.add(fruit5);

		// iterator for Fruits
		Iterator ite = listOfFruits.iterator();
		while (ite.hasNext()) {
			Fruit eFruit = (Fruit) ite.next();// Type casting Fruit

			// Printing the Fruits Information
			System.out.println("Name of the fruit:    " + eFruit.getName());
			System.out.println("Color of the fruit:   " + eFruit.getColor());
			System.out.println("Taste of the fruit:   " + eFruit.getTaste());
			System.out.println("Price of the fruit:   " + eFruit.getPrice());
			System.out.println("****************************");
		}

	}

}
